Conversation
Emm... It's not really the same thing. defer is more general. |
|
I am mostly neutral (though slightly negative) on the defer class here,
because it can be implemented using std::unique_ptr without too much
complication. However, I like defer as a general cleanup as in golang.
…On Sat, Nov 7, 2020, 03:00 Allen ***@***.***> wrote:
Class defer seems to be duplicating the function of std::unique_ptr. I
don't know how @serizba <https://github.com/serizba> feels about it.
Emm... It's not really the same thing. defer is more general.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#69 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AALDTHWKZDK4GO6SQK75NEDSOT5A3ANCNFSM4TNPMYCA>
.
|
|
I do not have a strong opinion on the topic either. I will accept the request if you both agree on it. If you think that just using |
|
@ivanallen I am sorry that I didn't get much time to test this, my apologies. The other @serizba I think this is good to go. Although gcc's leak sanitizer still shows leaks in libcuda.so, I think it is false positive. If you still prefer |
|
I list the difference between
std::vector<TF_Tensor*> inp_val(inputs.size());
+ defer d([&inp_val]{
+ for (auto* tf_tensor : inp_val) TF_DeleteTensor(tf_tensor);
+ });
+ std::vecotr<std::unique_ptr<TF_Tenosr, decltype(&TF_DeleteTensor)>> inp_val_ptr;
std::vector<TF_Tensor*> inp_val(inputs.size());
//...
for (...) {
// ...
auto inp_tensor = TFE_TensorHandleResolve(std::get<1>(inputs[i]).tfe_handle.get(), context::get_status());
+ inp_val_ptr.emplace_back(inp_tensor, TF_DeleteTensor);
+ inp_val[i] = inp_tensor; // copy raw pointer to anther vector
}
//... |
|
I think @serizba should be the person to make the final decision here :) |
|
Thanks for showing both options @ivanallen, Now I think that perhaps using |
ivanallen
left a comment
There was a problem hiding this comment.
New problems will be resolved in a new pull request.
Fix memory leak.